<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <title>个人中心</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/common.css" />
    <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../css/aui-pull-refresh.css" />
    <style>
      #header_top {
        background: #ff0137;
      }
      #header_top .aui-title {
        color: #fff;
      }
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav" id="header_top">
        <a class="aui-pull-left aui-btn" onclick="goback()">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title">定位</div>
    </header>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript" src="../../script/jquery.charfirst.pinyin.js"></script>
<script type="text/javascript" src="../../script/sort.js"></script>
<script type="text/javascript">
    function goback() {
        api.closeWin()
    }
    apiready = function() {
        var header_top = $api.byId('header_top');
        var header_topPos = $api.offset(header_top);
        var UICityList = api.require('UICityList');
        var bMap = api.require('bMap');
        bMap.getLocation({
            accuracy: '10m',
            autoStop: true,
            filter: 1
        }, function(ret, err) {
            if (ret.status) {
                bMap.getNameFromCoords({
                    lon: ret.lon,
                    lat: ret.lat
                }, function(r, e) {
                    if (r.status) {
                      UICityList.open({
                          rect: {
                              x: 0,
                              y: header_topPos.h,
                              w: api.frameWidth,
                              h: api.frameHeight - header_topPos.h
                          },
                          resource: 'widget://res/cityList.json',
                          styles: {
                              searchBar: {
                                  bgColor: '#f7f7f7',
                                  cancelColor: '#E3E3E3'
                              },
                              location: {
                                  color: '#696969',
                                  size: 12
                              },
                              sectionTitle: {
                                  bgColor: '#f7f7f7',
                                  color: '#000',
                                  size: 12
                              },
                              item: {
                                  bgColor: '#fff',
                                  activeBgColor: '#fff',
                                  color: '#000',
                                  size: 14,
                                  height: 40
                              },
                              indicator: {
                                  bgColor: '#fff',
                                  color: '#696969'
                              }
                          },
                          currentCity: r.city,
                          locationWay: '当前定位城市',
                          hotTitle: '热门城市',
                          fixedOn: api.frameName,
                          placeholder: '输入城市名或首字母查询'
                      }, function(re, er) {
                          if (re) {
                            if(re.eventType == 'selected') {
                              // api.toast({ msg: re.cityInfo.city,duration: 2000,location:'middle' });

                              api.ajax({
                                  url: window.Url.Freeucenter_setUserInfo,
                                  method: 'post',
                                  data: {
                                      values: {
                                          token:$api.getStorage('token'),
                                          address: re.cityInfo.city
                                      }

                                  }
                              },function(ret0, err0){
                                  if (ret0) {
                                      // alert( JSON.stringify( ret ) );
                                      api.execScript({
                                        name: 'person',
                                        frameName: 'personMsg_list',
                                        script: 'window.location.reload()'
                                      })
                                      api.closeWin();

                                  } else {
                                      alert( JSON.stringify( err0 ) );
                                  }
                              });

                            }

                          } else {
                              console.log(JSON.stringify(er));
                          }
                      });
                    }
                });
            } else {
                alert(err.code);
            }
        });


    };
</script>

</html>
